package com.unitedats.common.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.unitedats.common.Entity.SysUserLogin;
import com.unitedats.common.bo.Message;

public class LoginProcessServlet extends BasicServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SysUserLogin user = new SysUserLogin();
		user.setUserName(request.getParameter("userName"));
		user.setPassword(request.getParameter("password"));
		//user.setStatue(true);

		List<SysUserLogin> list = dbm.find(user);

		if (list == null || list.size() == 0) {
			setMessage(request, new Message("User name or password is not correct", Message.MESSAGE_TYPE.ERROR));
			basicForward(request, response, "Logout");
			return;
		}
		user = list.get(0);
		
		setSessionUser(request, user);
		setMessage(request, new Message("You have logged in successfully", Message.MESSAGE_TYPE.SUCCESS));
		sendRedirect(request, response, "WelcomeDisplay");
	}
}
